package com.weiyuwqj.app.mobile.account;

import com.weiyuwqj.api.common.PageList;
import com.weiyuwqj.api.common.Paginator;
import com.weiyuwqj.api.exception.CrowdException;
import com.weiyuwqj.api.model.BusAccount;
import com.weiyuwqj.api.model.BusIncomeStat;
import com.weiyuwqj.api.service.*;
import com.weiyuwqj.api.util.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Administrator on 2016/1/8.
 */
@Controller
@RequestMapping(value = "/mobile/account")
public class MobileAccountController {

    @Autowired
    private BusAccountService accountService;

    @Autowired
    private BusIncomeStatService incomeStatService;

    @Autowired
    private BusAccountLogService accountLogService;

    @Autowired
    private BusInvestCollectService collectService;

    @Autowired
    private BusInvestService investService;


    /**
     * 账户
     * @param userId 用户ID
     * @return 账户信息
     */
    @ResponseBody
    @RequestMapping(value="/accountPage",method = RequestMethod.POST)
    public Object accountPage(Integer userId){
        BusAccount account=accountService.getBusAccountByUserId(userId);
        return account;
    }

    /**
     * 总资产
     */
    @ResponseBody
    @RequestMapping(value="/income")
    public Object income(Integer userId){
        Map returnMap=new HashMap();
        BusAccount account=accountService.getBusAccountByUserId(userId);
        returnMap.put("accountUsable", account.getUsable()+"");
        returnMap.put("accountFrozen", account.getFrozen()+"");
        returnMap.put("totalAccount", account.getTotal()+"");
        returnMap.put("cashAccount", account.getCash()+"");
        returnMap.put("income", incomeStatService.getOneByUserId(userId).getTotalIncome()+"");
        returnMap.put("yesterdayIncome", collectService.countYesterdayIncome(userId)+"");
        returnMap.put("thisMonthIncome", collectService.countMonthIncome(userId)+"");
        return returnMap;
    }

    /**
     * 投资中记录
     * @return 投资中记录
     */
    @ResponseBody
    @RequestMapping(value = "/accountWaitFund",method = RequestMethod.POST)
    public Object getWaitFundLog(Paginator p,Integer userId) {
        Map param = new HashMap();
        param.put("userId", userId); // 用户ID
        param.put("investStatus", 1); // 复审通过 投资中
        return investService.getList(p, param);
    }

    /**
     * 获取账户明细
     * @param p 分页信息
     * @param userId 用户ID
     * @return 账户明细
     */
    @ResponseBody
    @RequestMapping(value = "/getAccountDetail",method = RequestMethod.POST)
    public Object accountDetail(Paginator p,Integer userId) {
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("userId" ,userId);
        param.put("remove", 1); // 移除不给用户看的明细
        return accountLogService.getList(p,param);
    }


}
